如何使用c ++检测Linux中串行端口上运行的缓冲区

您所在的位置:网站首页 linux core文件生成 如何使用c ++检测Linux中串行端口上运行的缓冲区

如何使用c ++检测Linux中串行端口上运行的缓冲区

#如何使用c ++检测Linux中串行端口上运行的缓冲区 | 来源: 网络整理| 查看: 265

本文介绍了如何使用c ++检测Linux中串行端口上运行的缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个大问题.目前我正在通过以下钩子访问串口:

I have a big problem. At present I am accessing a serial port via the following hooks:

fd = open( "/dev/ttyS1", O_RDWR | O_NOCTTY )

然后我使用以下代码块从中读取

then I read from it using the following chunk of code

i = select( fd + 1, &rfds, NULL, NULL, &tv ) ... iLen = read( fd, buf, MAX_PACKET_LEN )

问题是在我阅读之前,我需要检测是否有任何缓冲区溢出.在串行端口级别和内部 tty 翻转缓冲区.

the problem is that before I read, I need to detect if there were any buffer overruns. Both at the serial port level and the internal tty flip buffers.

我们尝试了 cat/proc/tty/driver/serial 但它似乎没有列出溢出(见下面的输出)

We tried cat /proc/tty/driver/serial but it doesn’t seem to list the overruns (see output below)

1: uart:16550A port:000002F8 irq:3 tx:70774 rx:862484 fe:44443 pe:270023 brk:30301 RTS|CTS|DTR

推荐答案

根据内核源码,你应该使用TIOCGICOUNT ioctl.第三个 ioctl 参数应该是指向以下结构的指针,在 中定义:

According to the kernel sources, you should use the TIOCGICOUNT ioctl. The third ioctl argument should be a pointer to the following struct, defined in :

/* * Serial input interrupt line counters -- external structure * Four lines can interrupt: CTS, DSR, RI, DCD */ struct serial_icounter_struct { int cts, dsr, rng, dcd; int rx, tx; int frame, overrun, parity, brk; int buf_overrun; int reserved[9]; };

我不知道是否每个驱动程序都检测到所有情况.

I don’t know if every driver detect all conditions however.

这篇关于如何使用c ++检测Linux中串行端口上运行的缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

如何使用c ++检测Linux中串行端口上运行的缓冲区 为WP2原创文章,链接:https://www.wp2.cn/other/%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8c-%e6%a3%80%e6%b5%8blinux%e4%b8%ad%e4%b8%b2%e8%a1%8c%e7%ab%af%e5%8f%a3%e4%b8%8a%e8%bf%90%e8%a1%8c%e7%9a%84%e7%bc%93%e5%86%b2%e5%8c%ba/



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3